package com.cf.config;

import com.cf.common.util.mapping.BeanMapper;
import com.cf.common.util.mapping.DefaultBeanMapper;
import com.cf.compent.location.City;
import com.cf.compent.rank.RankService;
import com.cf.compent.rank.UserKeyFormatter;
import com.cf.compent.rank.impl.DefaultUserKeyFormatter;
import com.cf.compent.rank.impl.RedisRankService;
import com.cf.core.player.UserInfoService;
import com.cf.core.player.impl.DefaultUserInfoService;
import com.cf.serialize.MessageConvertService;
import com.cf.serialize.common.CommonMessageRegister;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * game-server-SysCommonConfig
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/5/7 下午 02:26
 */

@Slf4j
@Configuration
public class SysCommonConfig {

    @Bean(name = "beanMapper")
    public BeanMapper beanMapper() {
        return new DefaultBeanMapper();
    }


    @Bean(name = "messageConvertService")
    public MessageConvertService messageConvertService() {
        return new MessageConvertService();
    }


    @Bean(name = "commonMessageRegister")
    public CommonMessageRegister commonMessageRegister() {
        return new CommonMessageRegister();
    }

    @Bean(name = "city")
    public City city() throws IOException {
        return new City();
    }


    @Bean(name = "userInfoService")
    @ConditionalOnMissingBean(UserInfoService.class)
    public UserInfoService userInfoService() {
        log.info("为找到用户的RankService，实例化默认的RankService【{}】", "RedisRankService");
        return new DefaultUserInfoService();
    }


    @Bean(name = "rankService")
    @ConditionalOnMissingBean(RankService.class)
    public RankService rankService() {
        log.info("为找到用户的RankService，实例化默认的RankService【{}】", "RedisRankService");
        return new RedisRankService();
    }

    @Bean(name = "userKeyFormatter")
    @ConditionalOnMissingBean(UserKeyFormatter.class)
    public DefaultUserKeyFormatter userKeyFormatter() {
        log.info("为找到用户的UserKeyFormatter，实例化默认的UserKeyFormatter【{}】", "DefaultUserKeyFormatter");
        return new DefaultUserKeyFormatter();
    }

}
